/*
观战列表界面，和玩家列表有区别;
玩家列表是指已经上过分的玩家(只要上过分不管当前在不在包厢内都会显示);
观战列表指的是在包厢内但是还没有坐到座位上的玩家;
*/
var confige = require("confige");
cc.Class({
    extends: cc.Component,

    properties: {
        player_item:{
            default:null,
            type:cc.Node
        },
        isInit:false,
    },

    onLoad: function () {

    },

    onInit:function(){
        this.playerContent = this.node.getChildByName("playerView").getChildByName("view").getChildByName("content");
        this.playerItemBeginY = -50;
        this.playerItemOffsetY = -60;

        this.playerItemList = {};
        this.curPlayerData = {};
        this.isInit = true;
    },

    updatePlayerList:function(){
        console.log("updatePlayerList@@@@@@======");
        console.log(this.curPlayerData);
        for(var i in this.playerItemList)
        {
            this.playerItemList[i].destroy();
        }
        this.playerItemList = {};

        var newContentHeight = 0;
        var playerItemCount = 0;
        var newPlayerItemY = this.playerItemBeginY;
        for(var i in this.curPlayerData)
        {
            playerItemCount++;

            var curPlayerData = this.curPlayerData[i].playerInfo;
            console.log("curPlayerData======");
            console.log(curPlayerData);

            var newHisPlayerCount = 0;
            for(var j in curPlayerData.player)
                newHisPlayerCount ++;
            var newPlayerItem = cc.instantiate(this.player_item);
            newPlayerItem.y = newPlayerItemY;
            this.playerItemList[i] = newPlayerItem;
            this.playerContent.addChild(newPlayerItem);
            newPlayerItem.active = true;
            newPlayerItemY += this.playerItemOffsetY;

            var newHead = newPlayerItem.getChildByName("headNode").getChildByName("head").getComponent("cc.Sprite");
            window.DKTools.setFrameWithUrl(curPlayerData.head,newHead);
            var hisIndex = newPlayerItem.getChildByName("index").getComponent("cc.Label");
            hisIndex.string = playerItemCount;
            var id = newPlayerItem.getChildByName("id").getComponent("cc.Label");
            id.string = i;
            var nick = newPlayerItem.getChildByName("nick").getComponent("cc.Label");
            nick.string = curPlayerData.nickname;
            var score = newPlayerItem.getChildByName("score").getComponent("cc.Label");
            score.string = this.curPlayerData[i].score;

        }
        if(newContentHeight < 500)
            newContentHeight = 500;
        this.playerContent.height = -newPlayerItemY + 100;
    },

    showLayer:function(){
        if(this.isInit == false)
            this.onInit();
        this.node.active = true;
        this.updatePlayerList();
    },

    hideLayer:function(){
        this.node.active = false;
    },
});
